import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'ruleName',
    label: '规则名称',
  },
];

// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '规则名称',
    field: 'ruleName',
  },
  {
    title: '项目名称',
    field: 'projectName',
  },
  {
    title: '实验名称',
    field: 'trialName',
  },
  {
    title: '描述',
    field: 'remark',
  },
  {
    title: '规则类型',
    field: 'triggerType',
    formatter: ({ cellValue }) => {
      return cellValue === 'SCHEDULED'
        ? '超时事件触发'
        : cellValue === 'EVENT_DRIVEN'
          ? '事件驱动'
          : '未知';
    },
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 180,
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    label: '主键ID',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '规则名称',
    fieldName: 'ruleName',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '所属项目',
    fieldName: 'projectId',
    component: 'ApiSelect',
    rules: 'required',
  },
  {
    label: '所属实验',
    fieldName: 'clinicalTrialId',
    component: 'Select',
    rules: 'required',
  },
  {
    label: '触发类型',
    fieldName: 'triggerType',
    component: 'RadioGroup',
    defaultValue: 'SCHEDULED',
    rules: 'required',
    componentProps: {
      buttonStyle: 'solid',
      optionType: 'button',
      options: [
        {
          label: '超时事件触发',
          value: 'SCHEDULED',
        },
        {
          label: '事件驱动',
          value: 'EVENT_DRIVEN',
        },
      ],
    },
  },
  {
    label: '启用状态',
    fieldName: 'isActive',
    component: 'RadioGroup',
    defaultValue: true,
    rules: 'required',
    componentProps: {
      buttonStyle: 'solid',
      optionType: 'button',
      options: [
        {
          label: '已启用',
          value: true,
        },
        {
          label: '未启用',
          value: false,
        },
      ],
    },
  },
  {
    component: 'Textarea',
    fieldName: 'remark',
    formItemClass: 'items-start',
    label: '备注',
  },
];
